package hai.com.android_test.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.ButterKnife;
import hai.com.android_test.ui.fragment.VpFragment;
import hai.com.android_test.widget.ViewPagerIndicator;

/**
 * Created by 黄海 on 2016/11/21.
 */

public class StickNavActivity extends AppCompatActivity {

    private List<String> mTitles = Arrays.asList("短信1", "收藏2", "推荐3", "短信4",
            "收藏5");
    List<Fragment> fragments=new ArrayList<>();
//    @BindView(R.id.stickNav_top)
    TextView stickNavTitle;
//    @BindView(R.id.stickNav_indicator)
    ViewPagerIndicator stickNavIndicator;
//    @BindView(R.id.stickNav_viewPage)
    ViewPager stickNavViewPage;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.sticknavlayout);
        ButterKnife.bind(this);

        init();
        stickNavIndicator.setTabItemTitles(mTitles);
        stickNavViewPage.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });
        stickNavIndicator.setViewPager(stickNavViewPage,0);


    }

    void init() {
        for (String title: mTitles) {
            VpFragment fragment = VpFragment.newInstance(title);
            fragments.add(fragment);
        }

    }


}
